#!/bin/bash

echo "Enter MySQL username who need to change pwd:"
read username

echo "Enter MySQL new password:"
read -s password

echo "Enter MySQL user's host (default: localhost):"
read host

# 如果未提供主机，则将主机设置为默认值 localhost
if [ -z "$host" ]; then
  host="localhost"
fi

# 创建MySQL用户
echo "Enter the root password"
mysql -u root -p -e "ALTER USER '$username'@'$host' IDENTIFIED BY '$password';" --connect-expired-password
echo "MySQL user '$username' password changed successfully."


